package views;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;


import com.grupp42.te.R;

import data.ScheduleActivityPlacer;
import entities.ScheduleActivity;
import entities.ScheduleDate;
import entities.ScheduleDay;

import android.app.Activity;
import android.os.Bundle;
import android.view.Display;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import android.widget.TextView;

/**
 * Schedule view gui class
 * 
 * @author Christian
 * 
 */
public class Schedule extends Activity {
	private ScheduleActivityPlacer sap;
	protected void onCreate(Bundle savedInstanceState) {
 
	super.onCreate(savedInstanceState);
	sap = new ScheduleActivityPlacer();
	TreeMap<ScheduleDate, ScheduleDay> scheduleMap;
	Object obj = this.getIntent().getSerializableExtra("scheduleMap");
	if(obj != null){
		//Android does not support typecasts to TreeMap, thus this is a workaround.
		scheduleMap = new TreeMap<ScheduleDate, ScheduleDay>((Map<ScheduleDate, ScheduleDay>)obj);

	} else {
		scheduleMap = new TreeMap<ScheduleDate, ScheduleDay>();
	}
	/* Sets the view to the dayschedule layout */
	setContentView(R.layout.dayschedule);
	//Sets the schedule to the rigth view
	FrameLayout schedule = (ScrollView) findViewById(R.id.scrollView1);
	
	//Sets the date over the schedule
	TextView dateText = (TextView) findViewById(R.id.dateText);
	

	//called when its running
	
	ScheduleDay sDay = new ScheduleDay();

    ScheduleActivity act1 = new ScheduleActivity("room", "teacher", "activityType", "subject",830 ,1015,"date", 2 ,1);
    ScheduleActivity act4 = new ScheduleActivity("room4", "teacher4", "activityType4", "subject4",900 ,1345,"date",2,2); 
    ScheduleActivity act2 = new ScheduleActivity("room1", "teacher1", "activityType1", "subject1",1030 ,1215,"date",2,1);
    ScheduleActivity act3 = new ScheduleActivity("room2", "teacher2", "activityType2", "subject2",1700 ,2100,"date",1,0);

	 ArrayList<ScheduleActivity> activites = new ArrayList<ScheduleActivity>(); 
	 activites.add(act4);
	 activites.add(act3);
	 activites.add(act1);
	 activites.add(act2);
	 sDay.setDay(14);
	 sDay.setMonth(10);
	 
	 dateText.setText(sDay.getDay() + "/" + sDay.getMonth());
	 sDay.setActivites(activites);
	 sDay = scheduleMap.get(scheduleMap.firstKey());
	 //this.sap.activitySorter(sDay);	 

		Display display = this.getWindowManager().getDefaultDisplay(); 
		int width = display.getWidth();
		//int height = display.getHeight();
		width -= 20;
	schedule.addView(new ScheduleDayDrawer(this,sDay, width));
	
	
	}


}
